﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using Microsoft.Practices.ServiceLocation;
using NCommon.Data;
using NCommon.Rules;

namespace MyPetShop.Domain
{
    public class ShoppingDetailOverStockValidator : IValidationRule<ShoppingDetail>
    {	
		public string ValidationMessage {
			get {
				throw new NotImplementedException();
			}
		}
    	
		public string ValidationProperty {
			get {
				throw new NotImplementedException();
			}
		}
    	
		public bool Validate(ShoppingDetail entity)
		{
			var itemRepository = ServiceLocator.Current.GetInstance<IRepository<Item>>();
			var item = itemRepository.Single(s => s.ItemId == entity.ItemId);
			
			if(item.Quantity < entity.Quantity)
				return false;
			else
				return true;
		}
    }
}
